home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 June: Reference Library / Dev.CD Jun 96 RL / Dev.CD Jun 96 RL.toast / Technical Documentation / develop / develop Issue 26 / develop Issue 26 code / Truffles - Display Mgr. / SuperFly source / SuperFly.cp < prev    next >
Encoding:
Text File  |  1996-01-18  |  4.1 KB  |  232 lines  |  [TEXT/CWIE]

  1. /*
  2.     File:        BigBrains.cp
  3.  
  4.     Contains:    Application-specific code for BigBrains.
  5.                 
  6.     Written by: Kent Miller
  7.  
  8.     Copyright:    © 1995-1996 by Kent Miller, all rights reserved.
  9.  
  10.     Change History (most recent first):
  11.      
  12.  */
  13.  
  14. #include <Displays.h>
  15.  
  16. //Sprocket Includes
  17. #include "Sprocket.h"
  18.  
  19. //App specific includes
  20. #include "SuperFly.h"
  21. #include "SuperFlyAppleEventHandler.h"
  22. #include "GDeviceUtilities.h"
  23. #include "GDeviceWindow.h"
  24.  
  25. //Application specific globals
  26. TLinkedList        *gMyWindowList;  //One for every active GDevice
  27. Boolean            mirroringWasOn;  //Was mirroring on when I started?
  28.  
  29. OSErr
  30. SetupApplication(void)
  31.     {    
  32.     OSErr    err = noErr;
  33.     
  34.     if (!gHasDisplayManager)
  35.         {
  36.         ErrorAlert(kErrorList, kNoDisplayManager);
  37.         gDone = true;
  38.         return -1;
  39.         }
  40.  
  41.     err = InstallDisplayManagerEventHandler();
  42.     DMIsMirroringOn(&mirroringWasOn);
  43.     InitCursor();
  44.     return err;
  45.     }
  46.  
  47.  
  48. void
  49. TearDownApplication(void)
  50.     {
  51.     Boolean     mirroringOnNow;
  52.     
  53.     SuperFlyTearDownMyWindows();
  54.     
  55.     DMIsMirroringOn(&mirroringOnNow);
  56.     if (mirroringWasOn != mirroringOnNow)
  57.         MirrorAllDisplays(mirroringWasOn); //Toggle state of mirroring
  58.     }
  59.  
  60. void
  61. HandleMenuCommand(MenuCommandID theCommand)
  62.     {
  63.     switch (theCommand)
  64.         {
  65.         case    cAbout:
  66.             AboutBox();
  67.             break;
  68.             
  69.         case    cMirroring:
  70.             Boolean mirroringOnNow;
  71.  
  72.             DMIsMirroringOn(&mirroringOnNow);
  73.             MirrorAllDisplays(!mirroringOnNow); //Toggle state of mirroring
  74.             break;
  75.     
  76.         case    cOpen:
  77.             break;
  78.     
  79.         case    cPageSetup:
  80.             break;
  81.         
  82.         case    cPrint:
  83.             break;
  84.             
  85.         case    cQuit:
  86.             gDone = true;
  87.             break;
  88.             
  89.         case    cCopy:
  90.         case    cCut:
  91.         case    cPaste:
  92.         case    cClear:
  93.             break;
  94.  
  95.         default:
  96.             break;
  97.         }
  98.     }
  99.  
  100. void
  101. HandleMenuSelection(MenuID /* theMenu */,MenuItemID /* theItem */)
  102.     {
  103.     }
  104.  
  105.  
  106. void
  107. WriteLocalClipboardToScrap(void)
  108.     {
  109.     TEToScrap();
  110.     }
  111.  
  112. void
  113. ReadLocalClipboardFromScrap(void)
  114.     {
  115.     TEFromScrap();
  116.     }
  117.  
  118.  
  119. OSErr
  120. CreateNewDocument(void)
  121.     {
  122.     if (!gMyWindowList)
  123.         SuperFlySetUpWindows();
  124.  
  125.     return noErr;
  126.     }
  127.  
  128.  
  129. OSErr
  130. OpenDocument(LetterDescriptor * /* theDocument */, void * /*unused*/)
  131.     {
  132.     return errAEEventNotHandled;
  133.     }
  134.  
  135.  
  136. OSErr
  137. PrintDocument(LetterDescriptor * /* theDocument */, void * /*unused*/)
  138.     {
  139.     return errAEEventNotHandled;
  140.     }
  141.  
  142.  
  143. Boolean
  144. QuitApplication(void)
  145.     {
  146.     return true;
  147.     }
  148.  
  149.  
  150.  
  151. /**********************
  152. Above this line are functions required by Sprocket.  Below this line is
  153. support routines for those routines. 
  154. ***********************/
  155.  
  156. void AboutBox(void)
  157. {
  158.     EventRecord e;
  159.  
  160.     gSplashWindow = new TSplashWindow;    
  161.     HiliteMenu(0);
  162.     do {
  163.         WaitNextEvent(everyEvent,&e,60,gMouseRegion);
  164.         }while (( e.what != mouseDown) && (e.what != keyDown));
  165.     delete gSplashWindow;    //    get rid of the splash screen
  166. }
  167.  
  168. void
  169. SuperFlyTearDownMyWindows(void)
  170. {
  171.     TGDeviceWindow *theWin;
  172.  
  173.     theWin = (TGDeviceWindow *)gMyWindowList->GetFirstListElem();
  174.     while (theWin)
  175.         {
  176.         gMyWindowList->RemoveFromList(theWin);
  177.         theWin->Close();
  178.         theWin = (TGDeviceWindow *)gMyWindowList->GetFirstListElem();
  179.         }
  180.     delete gMyWindowList;
  181. }
  182.  
  183. OSErr
  184. SuperFlySetUpWindows(void)
  185. {
  186.     GDHandle             theGD;
  187.     TGDeviceWindow         *newWin;
  188.     TLinkedList            *myGDList;
  189.     
  190.     if (gMyWindowList)
  191.         SuperFlyTearDownMyWindows();
  192.     
  193.     myGDList = BuildAListOfUniqueDevices();
  194.  
  195.     gMyWindowList = new TLinkedList;
  196.     
  197.     theGD = (GDHandle) myGDList->GetFirstListElem();
  198.     while (theGD)
  199.         {
  200.         newWin = new TGDeviceWindow;
  201.         gMyWindowList->AddToList( newWin );
  202.         newWin->SetUpData( theGD );
  203.         theGD = (GDHandle) myGDList->GetNextListElem( theGD );
  204.         }    
  205.  
  206.  
  207.     delete    myGDList;
  208.  
  209.     return noErr;    
  210. }
  211.  
  212. void    
  213. SuperFlyHandleGDevicesMoved(void)
  214. //This function is called by the Display Manager Apple Event handler in AppleEventHandling.cp.
  215. //It's purpose is to loop through the currently active windows and ensure that each window is still
  216. //completely on it's device.  If it isn't, it will center the window on it's device.
  217. //
  218. //If your application doesn't set the Display Manager Aware bit in it's size resource,
  219. //the Display Manager will move the windows for you.  You just can't be sure where they will
  220. //end up.
  221. {
  222.     TGDeviceWindow        *theWin;
  223.  
  224.     theWin = (TGDeviceWindow *) gMyWindowList->GetFirstListElem();
  225.     
  226.     while (theWin)
  227.         {
  228.         theWin->WindowOnDevice();
  229.         theWin = (TGDeviceWindow *) gMyWindowList->GetNextListElem(theWin);
  230.         }
  231. }
  232.